/*
 * Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <tencentcloud/emr/v20190103/model/JobFlowResource.h>

using TencentCloud::CoreInternalOutcome;
using namespace TencentCloud::Emr::V20190103::Model;
using namespace rapidjson;
using namespace std;

JobFlowResource::JobFlowResource() :
    m_specHasBeenSet(false),
    m_instanceTypeHasBeenSet(false),
    m_tagsHasBeenSet(false),
    m_diskGroupsHasBeenSet(false)
{
}

CoreInternalOutcome JobFlowResource::Deserialize(const Value &value)
{
    string requestId = "";


    if (value.HasMember("Spec") && !value["Spec"].IsNull())
    {
        if (!value["Spec"].IsString())
        {
            return CoreInternalOutcome(Error("response `JobFlowResource.Spec` IsString=false incorrectly").SetRequestId(requestId));
        }
        m_spec = string(value["Spec"].GetString());
        m_specHasBeenSet = true;
    }

    if (value.HasMember("InstanceType") && !value["InstanceType"].IsNull())
    {
        if (!value["InstanceType"].IsString())
        {
            return CoreInternalOutcome(Error("response `JobFlowResource.InstanceType` IsString=false incorrectly").SetRequestId(requestId));
        }
        m_instanceType = string(value["InstanceType"].GetString());
        m_instanceTypeHasBeenSet = true;
    }

    if (value.HasMember("Tags") && !value["Tags"].IsNull())
    {
        if (!value["Tags"].IsArray())
            return CoreInternalOutcome(Error("response `JobFlowResource.Tags` is not array type"));

        const Value &tmpValue = value["Tags"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            Tag item;
            CoreInternalOutcome outcome = item.Deserialize(*itr);
            if (!outcome.IsSuccess())
            {
                outcome.GetError().SetRequestId(requestId);
                return outcome;
            }
            m_tags.push_back(item);
        }
        m_tagsHasBeenSet = true;
    }

    if (value.HasMember("DiskGroups") && !value["DiskGroups"].IsNull())
    {
        if (!value["DiskGroups"].IsArray())
            return CoreInternalOutcome(Error("response `JobFlowResource.DiskGroups` is not array type"));

        const Value &tmpValue = value["DiskGroups"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            DiskGroup item;
            CoreInternalOutcome outcome = item.Deserialize(*itr);
            if (!outcome.IsSuccess())
            {
                outcome.GetError().SetRequestId(requestId);
                return outcome;
            }
            m_diskGroups.push_back(item);
        }
        m_diskGroupsHasBeenSet = true;
    }


    return CoreInternalOutcome(true);
}

void JobFlowResource::ToJsonObject(Value &value, Document::AllocatorType& allocator) const
{

    if (m_specHasBeenSet)
    {
        Value iKey(kStringType);
        string key = "Spec";
        iKey.SetString(key.c_str(), allocator);
        value.AddMember(iKey, Value(m_spec.c_str(), allocator).Move(), allocator);
    }

    if (m_instanceTypeHasBeenSet)
    {
        Value iKey(kStringType);
        string key = "InstanceType";
        iKey.SetString(key.c_str(), allocator);
        value.AddMember(iKey, Value(m_instanceType.c_str(), allocator).Move(), allocator);
    }

    if (m_tagsHasBeenSet)
    {
        Value iKey(kStringType);
        string key = "Tags";
        iKey.SetString(key.c_str(), allocator);
        value.AddMember(iKey, Value(kArrayType).Move(), allocator);

        int i=0;
        for (auto itr = m_tags.begin(); itr != m_tags.end(); ++itr, ++i)
        {
            value[key.c_str()].PushBack(Value(kObjectType).Move(), allocator);
            (*itr).ToJsonObject(value[key.c_str()][i], allocator);
        }
    }

    if (m_diskGroupsHasBeenSet)
    {
        Value iKey(kStringType);
        string key = "DiskGroups";
        iKey.SetString(key.c_str(), allocator);
        value.AddMember(iKey, Value(kArrayType).Move(), allocator);

        int i=0;
        for (auto itr = m_diskGroups.begin(); itr != m_diskGroups.end(); ++itr, ++i)
        {
            value[key.c_str()].PushBack(Value(kObjectType).Move(), allocator);
            (*itr).ToJsonObject(value[key.c_str()][i], allocator);
        }
    }

}


string JobFlowResource::GetSpec() const
{
    return m_spec;
}

void JobFlowResource::SetSpec(const string& _spec)
{
    m_spec = _spec;
    m_specHasBeenSet = true;
}

bool JobFlowResource::SpecHasBeenSet() const
{
    return m_specHasBeenSet;
}

string JobFlowResource::GetInstanceType() const
{
    return m_instanceType;
}

void JobFlowResource::SetInstanceType(const string& _instanceType)
{
    m_instanceType = _instanceType;
    m_instanceTypeHasBeenSet = true;
}

bool JobFlowResource::InstanceTypeHasBeenSet() const
{
    return m_instanceTypeHasBeenSet;
}

vector<Tag> JobFlowResource::GetTags() const
{
    return m_tags;
}

void JobFlowResource::SetTags(const vector<Tag>& _tags)
{
    m_tags = _tags;
    m_tagsHasBeenSet = true;
}

bool JobFlowResource::TagsHasBeenSet() const
{
    return m_tagsHasBeenSet;
}

vector<DiskGroup> JobFlowResource::GetDiskGroups() const
{
    return m_diskGroups;
}

void JobFlowResource::SetDiskGroups(const vector<DiskGroup>& _diskGroups)
{
    m_diskGroups = _diskGroups;
    m_diskGroupsHasBeenSet = true;
}

bool JobFlowResource::DiskGroupsHasBeenSet() const
{
    return m_diskGroupsHasBeenSet;
}

